/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package KASystem;

import javax.swing.JDialog;
import javax.swing.JOptionPane;

/**
 *
 * @author DJH
 */
public class AddHotel extends javax.swing.JPanel {

    private ConferenceHandler conferencehandeler;

    /**
     * Creates new form AddHotel
     */
    public AddHotel(ConferenceHandler handler) {
        conferencehandeler = handler;
        initComponents();
    }

    private void addHotel() {
        String name = nameArea.getText();
        String description = descriptionArea.getText();

        int singlePrice = -1;

        while (singlePrice == -1) {
            try {
                singlePrice = Integer.parseInt(priceArea.getText());
            } catch (Exception e) {
                String num = JOptionPane.showInputDialog(this, "Single price must be a number, please input a new price.");
                try {
                    singlePrice = Integer.parseInt(num);
                } catch (Exception e2) {
                }
            }
        }

        int doublePrice = -1;

        while (doublePrice == -1) {
            try {
                doublePrice = Integer.parseInt(dPriceArea.getText());
            } catch (Exception e) {
                String num = JOptionPane.showInputDialog(this, "Double price must be a number, please input a new price.");
                try {
                    doublePrice = Integer.parseInt(num);
                } catch (Exception e2) {
                }
            }
        }

        System.out.println("lol");
        
        int additionPrice = -1;
        
        while (additionPrice == -1) {
            
            if(aPriceTextArea.getText().isEmpty()){
                    additionPrice = 0;
                    break;
                }
            
            try {
                additionPrice = Integer.parseInt(aPriceTextArea.getText());
            } catch (Exception e) {
                String num = JOptionPane.showInputDialog(this, "Addition price must be a number, please input a new price.");
                try {
                    additionPrice = Integer.parseInt(num);
                } catch (Exception e2) {
                }
            }
        }
        System.out.println("BLAH");

        Hotel temp = new Hotel(name, description, singlePrice, doublePrice);
        temp.setAdditionPrice(additionPrice);
        conferencehandeler.addHotel(temp);
    }

    private void close() {
        JDialog jd = (JDialog) this.getParent().getParent().getParent();
        jd.dispose();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        CancelButton = new javax.swing.JButton();
        AddButton = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        nameArea = new javax.swing.JTextField();
        descriptionArea = new javax.swing.JTextField();
        priceArea = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        dPriceArea = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        aPriceTextArea = new javax.swing.JTextField();

        jLabel1.setText("New Hotel");

        CancelButton.setText("Cancel");
        CancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelButtonActionPerformed(evt);
            }
        });

        AddButton.setText("Add");
        AddButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddButtonActionPerformed(evt);
            }
        });

        jLabel2.setText("Name");

        jLabel3.setText("Description");

        jLabel4.setText("Single Price");

        jLabel5.setText("Double Price");

        dPriceArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dPriceAreaActionPerformed(evt);
            }
        });

        jLabel6.setText("Addition Price");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(AddButton)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(nameArea, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(descriptionArea, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(priceArea, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(CancelButton, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(dPriceArea, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                            .addComponent(aPriceTextArea)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(108, 108, 108)
                        .addComponent(jLabel1)))
                .addContainerGap(39, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(nameArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(descriptionArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(priceArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dPriceArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6)
                    .addComponent(aPriceTextArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 74, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CancelButton)
                    .addComponent(AddButton))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddButtonActionPerformed
        addHotel();
        close();
    }//GEN-LAST:event_AddButtonActionPerformed

    private void CancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelButtonActionPerformed
        close();
    }//GEN-LAST:event_CancelButtonActionPerformed

    private void dPriceAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dPriceAreaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dPriceAreaActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AddButton;
    private javax.swing.JButton CancelButton;
    private javax.swing.JTextField aPriceTextArea;
    private javax.swing.JTextField dPriceArea;
    private javax.swing.JTextField descriptionArea;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField nameArea;
    private javax.swing.JTextField priceArea;
    // End of variables declaration//GEN-END:variables
}
